***This do-file creates Figure O3 of the paper
**Curtis RESTAT
**Change to directory where data and code were downloaded
**cd 

set matsize 1500
clear all
set more off

use cbprawstind3_figureO4,clear

drop if enint==0 /*keeps only MFTG Industries*/
drop if fipstate=="11" /*Drops DC*/

do dataclean_figureO4.do

gen empweight2=emp if year==1998
bysort stateind:carryforward empweight2,replace

so stateind year
egen empweight3t=mean(emp),by(stateind post)
replace empweight3t=. if post==1
egen empweight3=max(empweight3t),by(stateind)

gen eaststr="east" if east==1
replace eaststr="west" if eaststr==""
gen eastind=eaststr+naics

drop yeardum*
tab year,gen(yeardum)

gen trend=year-1997
qui tab fipstate,gen(STdum)
foreach var of varlist ind1-ind21 {
qui gen trend`var'=`var'*trend
}

foreach x of varlist STdum1-STdum49 {
qui gen trend`x'=`x'*trend
}

/* Generate Seperate East/West Trends by Industry*/
forvalues i = 1(1)21 {
  qui gen eindtrend`i' = trendind`i'*east
 }
forvalues i = 1(1)21 {
  qui gen windtrend`i' = trendind`i'*((east-1)^2)
 }
tostring east,replace
gen yearindreg=yearind+"_"+east


qui tab yearind,gen(yearinddum)
qui tab STyear, gen(STyeardum)
qui tab stateind, gen(stateinddum)

/* Defines RHS variables to be included in every regression*/
mac def rhs_vars "postxint intxeast postxeast  "

forvalues i = 1(1)21 {
  qui gen postxeastxind`i' = postxeast*ind`i'
 }


qui areg lemp postxeastxind1-postxeastxind21 postxeast postxint intxeast yearinddum* windtrend* eindtrend* [aweight=empweight2],abs(stateind) rob cluster(eastind)


parmest,norestore
keep in 1/21

gen ind_num=substr(parm,14,.)
so ind_num
replace estimate=estimate
merge 1:1 ind_num using ind_names_figureO4
drop if naics_name==""
gen pos=3
replace pos=1 if naics_name=="Transportation Equipment"
replace pos=5 if naics_name=="Chemicals"
replace pos=5 if naics3==337
replace pos=4 if naics3==311
replace pos=1 if naics3==313
replace pos=1 if naics3==339
replace pos=11 if naics3==333
replace pos=4 if naics3==315
replace pos=6 if naics3==316
replace pos=6 if naics3==331

twoway (lfit estimate en_int) (scatter estimate en_int,mlabel(naics_name) mlabv(pos)) 

**Below is the polynomial fit figure made for the referees
**twoway (fpfit estimate en_int) (scatter estimate en_int,mlabel(naics_name) mlabv(pos)) 

